package com.itheima.api.treeset.demo05;

import java.util.Comparator;
import java.util.Scanner;
import java.util.TreeSet;

public class TreeSetDemo05 {

    public static void main(String[] args) {
        //匿名内部类的方式
//        TreeSet<Student> studentTreeSet = new TreeSet<>(new Comparator<Student>() {
//            @Override
//            public int compare(Student o1, Student o2) {
//                int i = o1.getTotalScore() - o2.getTotalScore();
//                int i1 = i == 0 ? o1.getChineseScore() - o2.getChineseScore() : i;
//                int i2 = i1 == 0 ? o1.getMathScore() - o2.getMathScore() : i1;
//                int i3 = i2 == 0 ? o1.getName().compareTo(o2.getName()) : i2;
//                return i3;
//            }
//        });

        TreeSet<Student> studentTreeSet = new TreeSet<Student>((o1, o2) -> {
            int i = o1.getTotalScore() - o2.getTotalScore();
            int i1 = i == 0 ? o1.getChineseScore() - o2.getChineseScore() : i;
            int i2 = i1 == 0 ? o1.getMathScore() - o2.getMathScore() : i1;
            int i3 = i2 == 0 ? o1.getName().compareTo(o2.getName()) : i2;
            return i3;
        });

        for (int i = 0; i < 3; i++) {
            Scanner scanner = new Scanner(System.in);
            System.out.println("请输入学生姓名");
            String name = scanner.next();
            System.out.println("请输入学生语文成绩");
            String chineseScore = scanner.next();
            System.out.println("请输入学生数学成绩");
            String mathScore = scanner.next();
            System.out.println("请输入学生英语成绩");
            String englishScore = scanner.next();

            Student student = new Student(name, Integer.parseInt(chineseScore), Integer.parseInt(mathScore), Integer.parseInt(englishScore));

            studentTreeSet.add(student);
        }

        for (Student s : studentTreeSet){
            System.out.println(s);
        }
    }
}
